package net.hn.hnms.biz.energy.controller;

import cn.hutool.core.date.DateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.energy.service.StatisticsService;
import net.hn.hnms.biz.energy.vo.HydropowerVo;
import net.hn.hnms.biz.energy.vo.MonthValue;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Api(value = "统计模块", tags = {"统计模块"})
@RestController
@RequestMapping("/statistics")
@EnableScheduling
public class StatisticsController extends BaseController {

    @Autowired
    private StatisticsService statisticsService;

    /**
     * 获取水电油气统计信息
     */
    @ApiOperation("获取水电油气统计信息")
//    @SaCheckPermission("dispatch:keepwatch:detail")
    @GetMapping("/getWaterStatistics")
    @AutoSetMineCode
    public R<HydropowerVo> getWaterStatistics(String mineCode) {
        return R.ok(statisticsService.getWaterStatistics(mineCode));
    }


    @ApiOperation("生产成本分析-生产用水")
//    @SaCheckPermission("mining:face:add")
    @GetMapping("/product/costWaterByYear")
    @AutoSetMineCode
    public R<Map<String, List<MonthValue>>> costWaterByYear(Integer year, String mineCode) {
        return R.ok(statisticsService.costWaterByYear(year == null ? DateUtil.year(new Date()) : year, null,mineCode));
    }



    @ApiOperation("生产成本分析-生产用水-月统计")
//    @SaCheckPermission("mining:face:add")
    @GetMapping("/product/costWaterByMonth")
    @AutoSetMineCode
    public R<Map<String, BigDecimal>> costOfPlace(@DateTimeFormat(pattern = "yyyy-MM") Date date,String mineCode) {
        Calendar calendar = Calendar.getInstance(); //创建Calendar 的实例
        calendar.add(Calendar.MONTH, -1);
        date = date == null ? calendar.getTime() : date;
        return R.ok(statisticsService.costOfPlace(DateUtil.year(date), DateUtil.month(date) + 1,mineCode));
    }









}
